package com.example.databinding;

import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil;
import androidx.databinding.ViewDataBinding;

import android.os.Bundle;

import com.example.databinding.bean.Idol;
import com.example.databinding.databinding.ActivityMainBinding;
import com.example.databinding.databinding.ActivitySubMainBinding;
import com.example.databinding.util.EventListener;

public class SubMainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //利用DataBinding导入布局 并且获取DataBinding对象
        ActivitySubMainBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_sub_main);
        //向xml文件中传递数据
        Idol idol = new Idol("迪丽热巴", 5);
        binding.setIdol(idol);
        //设置点击事件
        binding.setEventListener(new EventListener(this));
    }
}